package{
	import com.tools.Tip;
	
	import flash.desktop.NativeDragManager;
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.events.NativeDragEvent;

	[SWF (width="1080",height="600")]
	public class Main extends Sprite{
		private var scene:SceneView;
		private var menu:MenuView;
		private var attr:AttrView;
		private var rule:Ruler;
		/**配置解析**/
		private var config:ConfigParsing;
		public function Main(){
			addEventListener(Event.ADDED_TO_STAGE,addToStage);
			stage.addEventListener(Event.RESIZE,resize);
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.align = StageAlign.TOP_LEFT;
		}
		private function addToStage(e:Event):void{
			attr=new AttrView();
			menu=new MenuView();
			scene=new SceneView();
			rule=new Ruler();
			addChild(scene);
			addChild(rule);
			addChild(menu);
			addChild(attr);
			Tip.stg=this.stage;
			resize(null);
			registerEvent();
			config=new ConfigParsing();
			config.loadConfig("config/config.xml");
			OutputParsing.loadConfig("config/output.xml");
		}
		private function registerEvent():void{
			stage.addEventListener(NativeDragEvent.NATIVE_DRAG_ENTER, setDrag);
			stage.addEventListener(NativeDragEvent.NATIVE_DRAG_DROP, scene.load);
			stage.addEventListener(MouseEvent.MOUSE_WHEEL,setScale);
		}
		/**设置允许拖入资源**/
		private function setDrag(e:NativeDragEvent):void{
			NativeDragManager.acceptDragDrop(scene);
		}
		/**设置显示比例**/
		private function setScale(e:MouseEvent):void{
			if(!e.currentTarget is Stage)return;
			if(e.delta>0){
				scene.panel.scaleX+=0.01;
				scene.panel.scaleY+=0.01;
			}else{
				scene.panel.scaleX-=0.01;
				scene.panel.scaleY-=0.01;
			}
		}
		private function resize(e:Event):void{
			scene.update();
			attr.update();
			menu.update();
			menu.y=this.stage.stageHeight-menu.height;
			attr.x=this.stage.stageWidth-attr.width;
			rule.update();
		}
	}
}